file(GLOB USER_SOURCES
    ${PROJ_APPLICATIONS_DIR}/*.c
    ${PROJ_SYSTEM_DIR}/*.c
    ${PROJ_USER_DIR}/*.c
)

set(USER_HEADERS
    ${PROJ_APPLICATIONS_DIR}
    ${PROJ_SYSTEM_DIR}
    ${PROJ_USER_DIR}
)

message(STATUS "User Source: ${USER_SOURCES}")
message(STATUS "User Header: ${USER_HEADERS}")

add_executable(${ELF_TARGET}
    ${USER_SOURCES}
    ${STARTUP_FILE}
)

target_include_directories(${ELF_TARGET} PUBLIC
    ${USER_HEADERS}
)
target_link_libraries(${ELF_TARGET} PUBLIC drivers middlewares -lc -lm)
target_link_libraries(${ELF_TARGET} PRIVATE -T${LINKER_SCRIPT} ${EXTRA_LINK_FLAGS})
target_compile_definitions(${ELF_TARGET} PUBLIC -D${MCU_FAMILY})

# 构建依赖
add_subdirectory(${PROJ_CMAKE_DIR}/drivers ${PROJ_ROOT_DIR}/build/CMake/drivers) # 构建 Drivers 库
add_subdirectory(${PROJ_CMAKE_DIR}/middlewares ${PROJ_ROOT_DIR}/build/CMake/middlewares) # 构建 middlewares 库
# 后处理
include(${PROJ_CMAKE_DIR}/cmake/postbuild.cmake)